{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "xls = pd.ExcelFile('数据透视表.xlsx')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "df = xls.parse('原数据')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>订购日期</th>\n",
       "      <th>所属区域</th>\n",
       "      <th>产品类别</th>\n",
       "      <th>数量</th>\n",
       "      <th>销售额</th>\n",
       "      <th>成本</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2007-03-21</td>\n",
       "      <td>苏州</td>\n",
       "      <td>宠物用品</td>\n",
       "      <td>16</td>\n",
       "      <td>19269.685164</td>\n",
       "      <td>18982.847760</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2007-04-28</td>\n",
       "      <td>苏州</td>\n",
       "      <td>宠物用品</td>\n",
       "      <td>40</td>\n",
       "      <td>39465.169800</td>\n",
       "      <td>40893.083149</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2007-04-28</td>\n",
       "      <td>苏州</td>\n",
       "      <td>宠物用品</td>\n",
       "      <td>20</td>\n",
       "      <td>21015.944745</td>\n",
       "      <td>22294.085221</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2007-05-31</td>\n",
       "      <td>苏州</td>\n",
       "      <td>宠物用品</td>\n",
       "      <td>20</td>\n",
       "      <td>23710.258593</td>\n",
       "      <td>24318.374118</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2007-06-13</td>\n",
       "      <td>苏州</td>\n",
       "      <td>宠物用品</td>\n",
       "      <td>16</td>\n",
       "      <td>20015.072431</td>\n",
       "      <td>20256.694699</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        订购日期 所属区域  产品类别  数量           销售额            成本\n",
       "0 2007-03-21   苏州  宠物用品  16  19269.685164  18982.847760\n",
       "1 2007-04-28   苏州  宠物用品  40  39465.169800  40893.083149\n",
       "2 2007-04-28   苏州  宠物用品  20  21015.944745  22294.085221\n",
       "3 2007-05-31   苏州  宠物用品  20  23710.258593  24318.374118\n",
       "4 2007-06-13   苏州  宠物用品  16  20015.072431  20256.694699"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "df['订购月']=df['订购日期'].apply(lambda x: f'{x.month}月')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr:last-of-type th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th colspan=\"6\" halign=\"left\">成本</th>\n",
       "      <th colspan=\"6\" halign=\"left\">销售额</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>所属区域</th>\n",
       "      <th>南京</th>\n",
       "      <th>常熟</th>\n",
       "      <th>无锡</th>\n",
       "      <th>昆山</th>\n",
       "      <th>苏州</th>\n",
       "      <th>All</th>\n",
       "      <th>南京</th>\n",
       "      <th>常熟</th>\n",
       "      <th>无锡</th>\n",
       "      <th>昆山</th>\n",
       "      <th>苏州</th>\n",
       "      <th>All</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>订购月</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>10月</th>\n",
       "      <td>237255.648092</td>\n",
       "      <td>4.830902e+05</td>\n",
       "      <td>454421.794007</td>\n",
       "      <td>346348.091177</td>\n",
       "      <td>4.354034e+05</td>\n",
       "      <td>1.956519e+06</td>\n",
       "      <td>310455.717729</td>\n",
       "      <td>6.110618e+05</td>\n",
       "      <td>5.052642e+05</td>\n",
       "      <td>4.688196e+05</td>\n",
       "      <td>5.049606e+05</td>\n",
       "      <td>2.400562e+06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11月</th>\n",
       "      <td>221687.106975</td>\n",
       "      <td>1.840869e+06</td>\n",
       "      <td>536866.768771</td>\n",
       "      <td>342420.180127</td>\n",
       "      <td>1.144810e+06</td>\n",
       "      <td>4.086652e+06</td>\n",
       "      <td>286329.880122</td>\n",
       "      <td>2.118504e+06</td>\n",
       "      <td>6.339154e+05</td>\n",
       "      <td>3.510232e+05</td>\n",
       "      <td>1.269351e+06</td>\n",
       "      <td>4.659123e+06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12月</th>\n",
       "      <td>808959.316248</td>\n",
       "      <td>2.629188e+05</td>\n",
       "      <td>856816.716180</td>\n",
       "      <td>951652.870814</td>\n",
       "      <td>3.021543e+05</td>\n",
       "      <td>3.182502e+06</td>\n",
       "      <td>894522.059924</td>\n",
       "      <td>3.244545e+05</td>\n",
       "      <td>1.040127e+06</td>\n",
       "      <td>1.096213e+06</td>\n",
       "      <td>3.479393e+05</td>\n",
       "      <td>3.703256e+06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1月</th>\n",
       "      <td>94967.835315</td>\n",
       "      <td>1.632201e+05</td>\n",
       "      <td>231822.279191</td>\n",
       "      <td>145403.321583</td>\n",
       "      <td>2.388120e+05</td>\n",
       "      <td>8.742255e+05</td>\n",
       "      <td>134313.607087</td>\n",
       "      <td>1.775315e+05</td>\n",
       "      <td>3.164181e+05</td>\n",
       "      <td>1.591834e+05</td>\n",
       "      <td>2.872540e+05</td>\n",
       "      <td>1.074701e+06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2月</th>\n",
       "      <td>138530.418156</td>\n",
       "      <td>1.268344e+05</td>\n",
       "      <td>376134.980954</td>\n",
       "      <td>86244.521785</td>\n",
       "      <td>9.141954e+04</td>\n",
       "      <td>8.191638e+05</td>\n",
       "      <td>187129.131409</td>\n",
       "      <td>1.544427e+05</td>\n",
       "      <td>4.640122e+05</td>\n",
       "      <td>1.023245e+05</td>\n",
       "      <td>1.059403e+05</td>\n",
       "      <td>1.013849e+06</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                 成本                                                            \\\n",
       "所属区域             南京            常熟             无锡             昆山            苏州   \n",
       "订购月                                                                             \n",
       "10月   237255.648092  4.830902e+05  454421.794007  346348.091177  4.354034e+05   \n",
       "11月   221687.106975  1.840869e+06  536866.768771  342420.180127  1.144810e+06   \n",
       "12月   808959.316248  2.629188e+05  856816.716180  951652.870814  3.021543e+05   \n",
       "1月     94967.835315  1.632201e+05  231822.279191  145403.321583  2.388120e+05   \n",
       "2月    138530.418156  1.268344e+05  376134.980954   86244.521785  9.141954e+04   \n",
       "\n",
       "                              销售额                                            \\\n",
       "所属区域           All             南京            常熟            无锡            昆山   \n",
       "订购月                                                                           \n",
       "10月   1.956519e+06  310455.717729  6.110618e+05  5.052642e+05  4.688196e+05   \n",
       "11月   4.086652e+06  286329.880122  2.118504e+06  6.339154e+05  3.510232e+05   \n",
       "12月   3.182502e+06  894522.059924  3.244545e+05  1.040127e+06  1.096213e+06   \n",
       "1月    8.742255e+05  134313.607087  1.775315e+05  3.164181e+05  1.591834e+05   \n",
       "2月    8.191638e+05  187129.131409  1.544427e+05  4.640122e+05  1.023245e+05   \n",
       "\n",
       "                                  \n",
       "所属区域            苏州           All  \n",
       "订购月                               \n",
       "10月   5.049606e+05  2.400562e+06  \n",
       "11月   1.269351e+06  4.659123e+06  \n",
       "12月   3.479393e+05  3.703256e+06  \n",
       "1月    2.872540e+05  1.074701e+06  \n",
       "2月    1.059403e+05  1.013849e+06  "
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pt = df.pivot_table(values=['销售额', '成本'], index=['订购月'], columns=['所属区域'], aggfunc=np.sum, margins=True)\n",
    "pt.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>成本</th>\n",
       "      <th>销售额</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>订购月</th>\n",
       "      <th>所属区域</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"5\" valign=\"top\">10月</th>\n",
       "      <th>南京</th>\n",
       "      <td>237255.648092</td>\n",
       "      <td>310455.717729</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>常熟</th>\n",
       "      <td>483090.201242</td>\n",
       "      <td>611061.779443</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>无锡</th>\n",
       "      <td>454421.794007</td>\n",
       "      <td>505264.207634</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>昆山</th>\n",
       "      <td>346348.091177</td>\n",
       "      <td>468819.554418</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>苏州</th>\n",
       "      <td>435403.430695</td>\n",
       "      <td>504960.559660</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                     成本            销售额\n",
       "订购月 所属区域                              \n",
       "10月 南京    237255.648092  310455.717729\n",
       "    常熟    483090.201242  611061.779443\n",
       "    无锡    454421.794007  505264.207634\n",
       "    昆山    346348.091177  468819.554418\n",
       "    苏州    435403.430695  504960.559660"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pts = pt.stack()\n",
    "pts.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>成本</th>\n",
       "      <th>销售额</th>\n",
       "      <th>利润</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>订购月</th>\n",
       "      <th>所属区域</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"5\" valign=\"top\">10月</th>\n",
       "      <th>南京</th>\n",
       "      <td>237255.648092</td>\n",
       "      <td>310455.717729</td>\n",
       "      <td>73200.069637</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>常熟</th>\n",
       "      <td>483090.201242</td>\n",
       "      <td>611061.779443</td>\n",
       "      <td>127971.578201</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>无锡</th>\n",
       "      <td>454421.794007</td>\n",
       "      <td>505264.207634</td>\n",
       "      <td>50842.413627</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>昆山</th>\n",
       "      <td>346348.091177</td>\n",
       "      <td>468819.554418</td>\n",
       "      <td>122471.463240</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>苏州</th>\n",
       "      <td>435403.430695</td>\n",
       "      <td>504960.559660</td>\n",
       "      <td>69557.128965</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                     成本            销售额             利润\n",
       "订购月 所属区域                                             \n",
       "10月 南京    237255.648092  310455.717729   73200.069637\n",
       "    常熟    483090.201242  611061.779443  127971.578201\n",
       "    无锡    454421.794007  505264.207634   50842.413627\n",
       "    昆山    346348.091177  468819.554418  122471.463240\n",
       "    苏州    435403.430695  504960.559660   69557.128965"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pts['利润'] = pts['销售额'] - pts['成本']\n",
    "pts.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr:last-of-type th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th colspan=\"5\" halign=\"left\">成本</th>\n",
       "      <th colspan=\"5\" halign=\"left\">销售额</th>\n",
       "      <th colspan=\"5\" halign=\"left\">利润</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>所属区域</th>\n",
       "      <th>南京</th>\n",
       "      <th>常熟</th>\n",
       "      <th>无锡</th>\n",
       "      <th>昆山</th>\n",
       "      <th>苏州</th>\n",
       "      <th>南京</th>\n",
       "      <th>常熟</th>\n",
       "      <th>无锡</th>\n",
       "      <th>昆山</th>\n",
       "      <th>苏州</th>\n",
       "      <th>南京</th>\n",
       "      <th>常熟</th>\n",
       "      <th>无锡</th>\n",
       "      <th>昆山</th>\n",
       "      <th>苏州</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>订购月</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>10月</th>\n",
       "      <td>237255.648092</td>\n",
       "      <td>4.830902e+05</td>\n",
       "      <td>4.544218e+05</td>\n",
       "      <td>346348.091177</td>\n",
       "      <td>4.354034e+05</td>\n",
       "      <td>310455.717729</td>\n",
       "      <td>6.110618e+05</td>\n",
       "      <td>5.052642e+05</td>\n",
       "      <td>4.688196e+05</td>\n",
       "      <td>5.049606e+05</td>\n",
       "      <td>73200.069637</td>\n",
       "      <td>127971.578201</td>\n",
       "      <td>50842.413627</td>\n",
       "      <td>122471.463240</td>\n",
       "      <td>69557.128965</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11月</th>\n",
       "      <td>221687.106975</td>\n",
       "      <td>1.840869e+06</td>\n",
       "      <td>5.368668e+05</td>\n",
       "      <td>342420.180127</td>\n",
       "      <td>1.144810e+06</td>\n",
       "      <td>286329.880122</td>\n",
       "      <td>2.118504e+06</td>\n",
       "      <td>6.339154e+05</td>\n",
       "      <td>3.510232e+05</td>\n",
       "      <td>1.269351e+06</td>\n",
       "      <td>64642.773147</td>\n",
       "      <td>277635.010651</td>\n",
       "      <td>97048.643763</td>\n",
       "      <td>8603.061581</td>\n",
       "      <td>124541.563529</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12月</th>\n",
       "      <td>808959.316248</td>\n",
       "      <td>2.629188e+05</td>\n",
       "      <td>8.568167e+05</td>\n",
       "      <td>951652.870814</td>\n",
       "      <td>3.021543e+05</td>\n",
       "      <td>894522.059924</td>\n",
       "      <td>3.244545e+05</td>\n",
       "      <td>1.040127e+06</td>\n",
       "      <td>1.096213e+06</td>\n",
       "      <td>3.479393e+05</td>\n",
       "      <td>85562.743676</td>\n",
       "      <td>61535.675507</td>\n",
       "      <td>183310.476259</td>\n",
       "      <td>144559.874958</td>\n",
       "      <td>45785.049217</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1月</th>\n",
       "      <td>94967.835315</td>\n",
       "      <td>1.632201e+05</td>\n",
       "      <td>2.318223e+05</td>\n",
       "      <td>145403.321583</td>\n",
       "      <td>2.388120e+05</td>\n",
       "      <td>134313.607087</td>\n",
       "      <td>1.775315e+05</td>\n",
       "      <td>3.164181e+05</td>\n",
       "      <td>1.591834e+05</td>\n",
       "      <td>2.872540e+05</td>\n",
       "      <td>39345.771772</td>\n",
       "      <td>14311.400330</td>\n",
       "      <td>84595.808798</td>\n",
       "      <td>13780.028760</td>\n",
       "      <td>48441.964821</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2月</th>\n",
       "      <td>138530.418156</td>\n",
       "      <td>1.268344e+05</td>\n",
       "      <td>3.761350e+05</td>\n",
       "      <td>86244.521785</td>\n",
       "      <td>9.141954e+04</td>\n",
       "      <td>187129.131409</td>\n",
       "      <td>1.544427e+05</td>\n",
       "      <td>4.640122e+05</td>\n",
       "      <td>1.023245e+05</td>\n",
       "      <td>1.059403e+05</td>\n",
       "      <td>48598.713253</td>\n",
       "      <td>27608.371476</td>\n",
       "      <td>87877.221492</td>\n",
       "      <td>16079.938519</td>\n",
       "      <td>14520.802736</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3月</th>\n",
       "      <td>72127.335747</td>\n",
       "      <td>6.439570e+05</td>\n",
       "      <td>6.079829e+05</td>\n",
       "      <td>90794.537244</td>\n",
       "      <td>6.995202e+05</td>\n",
       "      <td>98528.155682</td>\n",
       "      <td>7.808950e+05</td>\n",
       "      <td>6.897657e+05</td>\n",
       "      <td>1.014473e+05</td>\n",
       "      <td>8.008249e+05</td>\n",
       "      <td>26400.819935</td>\n",
       "      <td>136937.975394</td>\n",
       "      <td>81782.878444</td>\n",
       "      <td>10652.766650</td>\n",
       "      <td>101304.687733</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4月</th>\n",
       "      <td>201217.124728</td>\n",
       "      <td>3.603025e+05</td>\n",
       "      <td>1.374695e+06</td>\n",
       "      <td>108014.191156</td>\n",
       "      <td>5.131019e+05</td>\n",
       "      <td>241869.875367</td>\n",
       "      <td>4.130478e+05</td>\n",
       "      <td>1.477886e+06</td>\n",
       "      <td>1.268237e+05</td>\n",
       "      <td>5.768313e+05</td>\n",
       "      <td>40652.750639</td>\n",
       "      <td>52745.297876</td>\n",
       "      <td>103190.698543</td>\n",
       "      <td>18809.513650</td>\n",
       "      <td>63729.362712</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5月</th>\n",
       "      <td>107478.132765</td>\n",
       "      <td>4.654815e+05</td>\n",
       "      <td>7.858451e+05</td>\n",
       "      <td>74048.314243</td>\n",
       "      <td>6.014858e+05</td>\n",
       "      <td>136967.377897</td>\n",
       "      <td>5.349301e+05</td>\n",
       "      <td>9.274551e+05</td>\n",
       "      <td>9.440796e+04</td>\n",
       "      <td>6.629640e+05</td>\n",
       "      <td>29489.245132</td>\n",
       "      <td>69448.668443</td>\n",
       "      <td>141609.964650</td>\n",
       "      <td>20359.649627</td>\n",
       "      <td>61478.209967</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6月</th>\n",
       "      <td>122405.358197</td>\n",
       "      <td>2.824576e+05</td>\n",
       "      <td>6.751000e+05</td>\n",
       "      <td>159851.243389</td>\n",
       "      <td>3.080422e+05</td>\n",
       "      <td>146488.916109</td>\n",
       "      <td>3.235172e+05</td>\n",
       "      <td>7.759295e+05</td>\n",
       "      <td>1.718686e+05</td>\n",
       "      <td>3.295837e+05</td>\n",
       "      <td>24083.557911</td>\n",
       "      <td>41059.622618</td>\n",
       "      <td>100829.550757</td>\n",
       "      <td>12017.384654</td>\n",
       "      <td>21541.518049</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7月</th>\n",
       "      <td>351528.203332</td>\n",
       "      <td>3.402800e+05</td>\n",
       "      <td>6.866244e+05</td>\n",
       "      <td>221681.619222</td>\n",
       "      <td>5.192344e+05</td>\n",
       "      <td>407179.324254</td>\n",
       "      <td>3.876269e+05</td>\n",
       "      <td>7.582082e+05</td>\n",
       "      <td>2.684001e+05</td>\n",
       "      <td>5.923887e+05</td>\n",
       "      <td>55651.120922</td>\n",
       "      <td>47346.955869</td>\n",
       "      <td>71583.820748</td>\n",
       "      <td>46718.478378</td>\n",
       "      <td>73154.290578</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8月</th>\n",
       "      <td>90578.173289</td>\n",
       "      <td>2.938512e+05</td>\n",
       "      <td>3.561251e+05</td>\n",
       "      <td>189805.350121</td>\n",
       "      <td>4.541309e+05</td>\n",
       "      <td>111106.931290</td>\n",
       "      <td>3.709878e+05</td>\n",
       "      <td>4.174139e+05</td>\n",
       "      <td>1.813462e+05</td>\n",
       "      <td>4.992947e+05</td>\n",
       "      <td>20528.758001</td>\n",
       "      <td>77136.558401</td>\n",
       "      <td>61288.816343</td>\n",
       "      <td>-8459.146714</td>\n",
       "      <td>45163.829066</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9月</th>\n",
       "      <td>212806.356428</td>\n",
       "      <td>6.177423e+05</td>\n",
       "      <td>5.673003e+05</td>\n",
       "      <td>458584.565545</td>\n",
       "      <td>4.053057e+05</td>\n",
       "      <td>260332.156568</td>\n",
       "      <td>7.160619e+05</td>\n",
       "      <td>6.657694e+05</td>\n",
       "      <td>5.115267e+05</td>\n",
       "      <td>4.764476e+05</td>\n",
       "      <td>47525.800141</td>\n",
       "      <td>98319.596294</td>\n",
       "      <td>98469.119222</td>\n",
       "      <td>52942.155417</td>\n",
       "      <td>71141.955287</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                 成本                                                           \\\n",
       "所属区域             南京            常熟            无锡             昆山            苏州   \n",
       "订购月                                                                            \n",
       "10月   237255.648092  4.830902e+05  4.544218e+05  346348.091177  4.354034e+05   \n",
       "11月   221687.106975  1.840869e+06  5.368668e+05  342420.180127  1.144810e+06   \n",
       "12月   808959.316248  2.629188e+05  8.568167e+05  951652.870814  3.021543e+05   \n",
       "1月     94967.835315  1.632201e+05  2.318223e+05  145403.321583  2.388120e+05   \n",
       "2月    138530.418156  1.268344e+05  3.761350e+05   86244.521785  9.141954e+04   \n",
       "3月     72127.335747  6.439570e+05  6.079829e+05   90794.537244  6.995202e+05   \n",
       "4月    201217.124728  3.603025e+05  1.374695e+06  108014.191156  5.131019e+05   \n",
       "5月    107478.132765  4.654815e+05  7.858451e+05   74048.314243  6.014858e+05   \n",
       "6月    122405.358197  2.824576e+05  6.751000e+05  159851.243389  3.080422e+05   \n",
       "7月    351528.203332  3.402800e+05  6.866244e+05  221681.619222  5.192344e+05   \n",
       "8月     90578.173289  2.938512e+05  3.561251e+05  189805.350121  4.541309e+05   \n",
       "9月    212806.356428  6.177423e+05  5.673003e+05  458584.565545  4.053057e+05   \n",
       "\n",
       "                销售额                                                          \\\n",
       "所属区域             南京            常熟            无锡            昆山            苏州   \n",
       "订购月                                                                           \n",
       "10月   310455.717729  6.110618e+05  5.052642e+05  4.688196e+05  5.049606e+05   \n",
       "11月   286329.880122  2.118504e+06  6.339154e+05  3.510232e+05  1.269351e+06   \n",
       "12月   894522.059924  3.244545e+05  1.040127e+06  1.096213e+06  3.479393e+05   \n",
       "1月    134313.607087  1.775315e+05  3.164181e+05  1.591834e+05  2.872540e+05   \n",
       "2月    187129.131409  1.544427e+05  4.640122e+05  1.023245e+05  1.059403e+05   \n",
       "3月     98528.155682  7.808950e+05  6.897657e+05  1.014473e+05  8.008249e+05   \n",
       "4月    241869.875367  4.130478e+05  1.477886e+06  1.268237e+05  5.768313e+05   \n",
       "5月    136967.377897  5.349301e+05  9.274551e+05  9.440796e+04  6.629640e+05   \n",
       "6月    146488.916109  3.235172e+05  7.759295e+05  1.718686e+05  3.295837e+05   \n",
       "7月    407179.324254  3.876269e+05  7.582082e+05  2.684001e+05  5.923887e+05   \n",
       "8月    111106.931290  3.709878e+05  4.174139e+05  1.813462e+05  4.992947e+05   \n",
       "9月    260332.156568  7.160619e+05  6.657694e+05  5.115267e+05  4.764476e+05   \n",
       "\n",
       "                利润                                                              \n",
       "所属区域            南京             常熟             无锡             昆山             苏州  \n",
       "订购月                                                                             \n",
       "10月   73200.069637  127971.578201   50842.413627  122471.463240   69557.128965  \n",
       "11月   64642.773147  277635.010651   97048.643763    8603.061581  124541.563529  \n",
       "12月   85562.743676   61535.675507  183310.476259  144559.874958   45785.049217  \n",
       "1月    39345.771772   14311.400330   84595.808798   13780.028760   48441.964821  \n",
       "2月    48598.713253   27608.371476   87877.221492   16079.938519   14520.802736  \n",
       "3月    26400.819935  136937.975394   81782.878444   10652.766650  101304.687733  \n",
       "4月    40652.750639   52745.297876  103190.698543   18809.513650   63729.362712  \n",
       "5月    29489.245132   69448.668443  141609.964650   20359.649627   61478.209967  \n",
       "6月    24083.557911   41059.622618  100829.550757   12017.384654   21541.518049  \n",
       "7月    55651.120922   47346.955869   71583.820748   46718.478378   73154.290578  \n",
       "8月    20528.758001   77136.558401   61288.816343   -8459.146714   45163.829066  \n",
       "9月    47525.800141   98319.596294   98469.119222   52942.155417   71141.955287  "
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pts.unstack()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
